<?php
/**
 * Login_Data_Usersession
 * user session initialization
 * 
 * @author Adrian Stolarski
 */
class Login_Data_Usersession implements Login_Data_Mainable, Login_Data_Preparable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved();
    }
    
    /**
     * main()
     * session initialize
     * 
     * @param array $variables
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach ($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        $this->prepare_query($variables);
        //echo $this->database_query;
        $this->database->prepare($this->database_query);
        $this->database->query();
        $session_array = $this->database->fetch('array');
        //var_dump($session_array);
        //die();
        $_SESSION['user_id'] = $session_array['user_id'];
        $_SESSION['access_level_id'] = $session_array['access_level_id'];
        $_SESSION['language_id'] = $session_array['language_id'];
        $_SESSION['user_banned'] = $session_array['user_banned'];
        $_SESSION['user_activity'] = $session_array['user_activity'];
        return $_SESSION;
    }
    
    /**
     * 
     * @param array $variables
     * database query initialization
     */
    public function prepare_query(array $variables = null) {
        $this->database_query = "SELECT "
                . "user_object.user_id, "
                . "user_object.access_level_id, "
                . "user_object.language_id, "
                . "user_object.user_banned, "
                . "user_object.user_activity"
                . " FROM "
                . "user_object"
                . " WHERE "
                . "user_id="
                .$variables['user_id'].
                " LIMIT 1;";
    }

}
